import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {

    public static List<Integer> generateAnswer(){
        Random random = new Random();
        List<Integer> list = new LinkedList<>();
        for (; list.size() < 4; ) {
            int num  = random.nextInt(10);
            if (!list.contains(num)){
                list.add(num);
            }
        }
        return list;
    }

    public static List<Integer> getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        List<Integer> list = new LinkedList<>();
        for (int i = 0; i < 4 ; i++) {
            list.add(scanner.nextInt());
        }
        return list;
    }

    public static  int compareGuessAnswer(List<Integer> one,List<Integer> two){
        int a = 0;
        int b = 0;
        for (int i = 0; i < one.size(); i++) {
            if (one.get(i).equals(two.get(i))){
                a++;
            }else if(one.contains(two.get(i))){
                b++;
            }

        }
        System.out.println(String.format("a=%s,b=%s",a,b));
        return a;

    }

    public static boolean isWin(int a){
        return a == 4 ? true : false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        do {
            List<Integer> one = NGuessNumber.generateAnswer();
            int play_num = 0;
            while (true){
                System.out.println("输入答案:");
                List<Integer> two = NGuessNumber.getPlayerInput();
                if (NGuessNumber.isWin(NGuessNumber.compareGuessAnswer(one,two))){
                    System.out.println("猜对了!");
                    break;
                }
                play_num++;
                if (play_num == 6){System.out.println("游戏机会没了!");break; }
            }
            System.out.println("继续游戏输入y/n");
        }while (scanner.next().equals("y") ? true : false);



    }



}
